package com.shen;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Scanner;

/**
 * Author:shen
 * CreateDate:2020/6/3.
 * Function:
 */
public class demo03 {
    static Scanner scanner=new Scanner(System.in);
    public static void main(String[] args) {
        System.out.println("请输入一个文件名：");
        String fileName=scanner.nextLine();
        File file=new File("E:/",fileName);
        if(file.exists()&&file.isFile()){
            FileInputStream fileInputStream=null;
            try {
                fileInputStream=new FileInputStream(file);
                byte[] bytes=new byte[fileInputStream.available()];
                int len;
                while ((len=fileInputStream.read(bytes))!=-1){
                    fileInputStream.read(bytes,0,len);
                }
                for (byte w:bytes){
                        System.out.println(w);
                }

            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }finally {
                try {
                    if(fileInputStream!=null){
                        fileInputStream.close();
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }else{
            System.out.println("请输入一个正确的文件！");
        }

    }



}
